<template>
  <div class="main_spac1">
    <div class="main_white padding10 paddingTop0">
      <div class="main_ti box">
        <el-tabs v-model="activeName" @tab-click="handleClick" class="box">
          <el-tab-pane label="全部" name=""></el-tab-pane>
          <el-tab-pane label="待审核" name="1"></el-tab-pane>
          <el-tab-pane label="备货中" name="2"></el-tab-pane>
          <el-tab-pane label="配送中" name="3"></el-tab-pane>
          <el-tab-pane label="已收货" name="4"></el-tab-pane>
          <el-tab-pane label="已取消" name="5"></el-tab-pane>
        </el-tabs>
        <el-checkbox
          v-model="look_canceled_list"
          class="marginLeft25"
          @change="canceledChange"
          >不显示已取消订单
        </el-checkbox>
      </div>
      <div class="mainor_form big-top">
        <el-form
          :inline="true"
          :model="form"
          class="demo-form-inline"
          ref="userListFrom"
          label-width="100px"
          id="form"
        >
          <el-form-item label="配送日期：" prop="sendTime">
            <el-date-picker
              v-model="sendTime"
              type="daterange"
              class="time220"
              :editable="false"
              unlink-panels
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="yyyy-MM-dd"
              :clearable="false"
              :picker-options="pickerOptions"
              @change="getArticleList"
            />
          </el-form-item>
          <el-form-item label="订单号：" prop="order_sn">
            <el-input
              v-model.trim="form.order_sn"
              placeholder="订单号"
              clearable
              class="wid220"
            ></el-input>
          </el-form-item>
          <el-form-item label="用户：" prop="uid">
            <change-user-input
              ref="changeUserInput_form"
              @sendValue="
                (data) => {
                  form.uid = data.info.user_id;
                }
              "
              @zidname="uidName"
              @clear="clearzid"
            ></change-user-input>
          </el-form-item>
          <MainFormBtn @reset="reset" @getSearchFor="getSearchFor" :loading="listLoading" :showBtn="moredata" />
          <div class="more el-form-item" @click="more">
            <span>更多</span>
            <i :class="[{ on: moredata }, ' el-icon-arrow-down']"></i>
          </div>
          <div class="clearfix"></div>
          <el-collapse-transition>
            <div v-show="moredata" style="width: 100%">
              <el-form-item label="菜谱订单号：" prop="package_menu_order_sn">
                <el-input
                  v-model.trim="form.package_menu_order_sn"
                  placeholder="菜谱订单号"
                  clearable
                  class="wid220"
                ></el-input>
              </el-form-item>
              <el-form-item label="子账号：" prop="zid">
                <el-select
                  v-model="form.zid"
                  placeholder="子账号"
                  class="wid220"
                  no-data-text
                  filterable
                  @change="getArticleList"
                >
                  <el-option
                    v-for="(zid_time, index) in zid_name"
                    :key="index"
                    :label="zid_time.nickname"
                    :value="zid_time.id"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="来源：" prop="from">
                <el-select
                  v-model.trim="form.from"
                  placeholder="来源"
                  class="wid220"
                  @change="getArticleList"
                >
                  <el-option label="所有" value="0"></el-option>
                  <el-option
                    v-for="(send_time, index) in list.from_list"
                    :key="index"
                    :label="send_time"
                    :value="parseInt(index) + 1"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="运费：" prop="is_delivery_id">
                <el-select
                  v-model.trim="form.is_delivery_id"
                  placeholder="运费"
                  class="wid220"
                  @change="getArticleList"
                >
                  <el-option label="所有" value="0"></el-option>
                  <el-option
                    v-for="(send_time, index) in list.is_delivery"
                    :key="index"
                    :label="send_time"
                    :value="parseInt(index) + 1"
                  ></el-option>
                </el-select>
              </el-form-item>
              <div class="clearfix"></div>
              <el-form-item label="支付方式：" prop="is_piroment_id">
                <el-select
                  v-model.trim="form.is_piroment_id"
                  placeholder="支付方式"
                  class="wid220"
                  @change="getArticleList"
                >
                  <el-option label="所有" value="0"></el-option>
                  <el-option
                    v-for="(send_time, index) in list.is_piroment"
                    :key="index"
                    :label="send_time"
                    :value="parseInt(index) + 1"
                  ></el-option>
                </el-select>
              </el-form-item>
              
              <el-form-item label="是否打印：" prop="is_print">
                <el-select
                  v-model.trim="form.is_print"
                  placeholder="是否打印"
                  class="wid220"
                  @change="getArticleList"
                >
                  <el-option label="所有" value="0"></el-option>
                  <el-option
                    v-for="(send_time, index) in list.is_print_list"
                    :key="index"
                    :label="send_time"
                    :value="parseInt(index) + 1"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item
                label="商品："
                prop="goods_spu_id"
                style="margin-right: 0"
              >
                <change-goods-input
                  ref="changeGoodsInput"
                  @clear="
                    () => {
                      this.form.goods_spu_id = '';
                    }
                  "
                  @sendValue="
                    (data) => {
                      this.form.goods_spu_id = data.id;
                    }
                  "
                ></change-goods-input>
              </el-form-item>
              <el-form-item label="配送时间：" prop="send_time_id">
                <el-select
                  v-model.trim="form.send_time_id"
                  placeholder="配送时间"
                  class="wid220"
                  @change="getArticleList"
                >
                  <el-option label="所有" value=""></el-option>
                  <el-option
                    v-for="(send_time, index) in list.send_time"
                    :key="index"
                    :label="send_time"
                    :value="parseInt(index)"
                  ></el-option>
                </el-select>
              </el-form-item>
              <div class="clearfix"></div>
              <el-form-item label="下单日期：" prop="createTime">
                <el-date-picker
                  v-model="createTime"
                  type="datetimerange"
                  :editable="false"
                  unlink-panels
                  class="time220"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  :clearable="false"
                  :picker-options="pickerOptions"
                  @change="getArticleList"
                />
              </el-form-item>
              <el-form-item
                label="收货信息："
                prop="contact"
                style="margin-right: 0"
              >
                <el-input
                  v-model.trim="form.contact"
                  placeholder="收货人/收货手机"
                  clearable
                  class="wid220"
                ></el-input>
              </el-form-item>

              <el-form-item label="用户分组：" prop="group_id">
                <el-select
                  v-model.trim="form.group_id"
                  placeholder="用户分组"
                  class="wid220"
                  @change="getArticleList"
                >
                  <el-option label="所有" value="0"></el-option>
                  <el-option
                    v-for="(group, index) in list.group"
                    :key="index"
                    :label="group"
                    :value="parseInt(index)"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="业务员：" prop="salesman_id">
                <el-select
                  v-model.trim="form.salesman_id"
                  placeholder="业务员"
                  class="wid220"
                  @change="getArticleList"
                >
                  <el-option label="所有" value="0"></el-option>
                  <el-option
                    v-for="(group, index) in list.salesman"
                    :key="index"
                    :label="group"
                    :value="parseInt(index)"
                  ></el-option>
                </el-select>
              </el-form-item>
              <div class="clearfix"></div>
              <el-form-item label="司机：" prop="driver_id">
                <el-select
                  v-model.trim="form.driver_id"
                  placeholder="司机"
                  class="wid220"
                  @change="getArticleList"
                >
                  <el-option label="所有" value="0"></el-option>
                  <el-option
                    v-for="(group, index) in list.driver"
                    :key="index"
                    :label="group"
                    :value="parseInt(index)"
                  ></el-option>
                </el-select>
              </el-form-item>
              <!-- <div class="clearfix"></div> -->
              <!-- <el-form-item label="订单状态" prop="status">
                <el-select
                  v-model.trim="form.status"
                  placeholder="订单状态"
                  class="wid220"
                >
                  <el-option label="所有" :value="parseInt(0)"></el-option>
                  <el-option
                    v-for="(order_status, index) in list.order_status_list"
                    :key="index"
                    :label="order_status"
                    :value="parseInt(index + 1)"
                  ></el-option>
                </el-select>
              </el-form-item> -->
              <el-form-item label="支付状态：" prop="pay_type">
                <el-select
                  v-model.trim="form.pay_type"
                  placeholder="支付状态"
                  class="wid220"
                  @change="getArticleList"
                >
                  <el-option label="所有" value=""></el-option>
                  <el-option
                    v-for="(pay_type, index) in list.pay_type_list"
                    :key="index"
                    :label="pay_type"
                    :value="parseInt(index + 1)"
                  ></el-option>
                </el-select>
              </el-form-item>
              <div class="clearfix"></div>
              <el-form-item label=" ">
                <MainFormBtn class="btn-bottom" @reset="reset" @getSearchFor="getSearchFor" :loading="listLoading" :showBtn="!moredata" />
              </el-form-item>
            </div>
          </el-collapse-transition>
        </el-form>
      </div>

      <div class="main-controls-wrap">
        <div class="mainor_sec">
          <router-link to="/order/list/add?id=add" class="mainor_tea mg-r-6">创建订单</router-link>
          <el-button class="mg-r-6 marginLeft10">
            <router-link to="/order/list/temporaryadd"
              >临时加单<el-tooltip
                class="item"
                effect="dark"
                placement="bottom"
              >
                <div slot="content">
                  适用用户临时加单，平台不希望跟<br />正常订单一样手动走完所有流程；<br />创建临时订单，系统会自动走完采购<br />、入库、分拣、出库、账单生成等操作
                </div>
                <svg
                  aria-hidden="true"
                  class="navbar_svg new_navbar_svg temporary_svg"
                  width="14"
                  height="14"
                >
                  <use xlink:href="#icon-summary_question" />
                </svg> </el-tooltip></router-link>
          </el-button>
          <el-button class="marginLeft10" @click="pldeliver" v-if="isPrintBtn"
            >批量打印<el-tooltip class="item" effect="dark" placement="bottom">
              <div slot="content">
                注释：打印机纸张需要后进纸，连续打印没有预览效果
              </div>
              <svg
                aria-hidden="true"
                class="navbar_svg new_navbar_svg"
                width="14"
                height="14"
              >
                <use xlink:href="#icon-summary_question" />
              </svg> </el-tooltip
          ></el-button>
          <el-button @click="importDialog" class="marginLeft10">导入订单</el-button>
          <!-- <el-popover placement="bottom" trigger="hover">
            <div class="order_dervie">
              <span @click="exportb(0)" class="order_dervie_content"
                >导出 excel</span
              >
              <span @click="exportb(1)">导出 csv</span>
            </div> -->
          <el-button class="marginLeft10" @click="exportb" style="padding: 9px 10px" slot="reference">导出订单</el-button>
          <!-- </el-popover> -->
          <p class="marginLeft10" @click="merge">
            <el-button
              >合并订单<el-tooltip
                class="item"
                effect="dark"
                placement="bottom"
              >
                <div slot="content">
                  注释：该操作将同一用户的多个订单进行合并
                </div>
                <svg
                  aria-hidden="true"
                  class="navbar_svg new_navbar_svg"
                  width="14"
                  height="14"
                >
                  <use xlink:href="#icon-summary_question" />
                </svg> </el-tooltip
            ></el-button>
          </p>
          <el-button @click="handleCancels" class="marginLeft10">批量取消</el-button>
          <el-button v-show="activeName == 3" class="marginLeft10" @click="bulkGoods" >批量收货</el-button>
          <el-button v-show="activeName == 4" class="marginLeft10" @click="bulkReceipt" >批量回单</el-button>
        </div>
      </div>

      <MainTable
        ref="orderTable"
        :loading="listLoading"
        :columns="orderListColumns"
        :tableData="list.list.data"
        showSelection
        :height="630"
        @sort-change="tableSortChange"
        @selection-change="handleSelectionChange"
        :fieidList="list.field"
        @row-dblclick="rowDblclick"
      >
        <template v-slot:nickname="{ row }">{{
          row.member
            ? row.member.nickname
            : row.nickname
          }}
          <span v-if="row.zid_info">
            【{{ row.zid_info.nickname }}】
          </span>
        </template>
        <template v-slot:status="{ row }">
          <span :class="'order' + row.order_status">
            {{ list.order_status_list[row.order_status] }}
          </span>
        </template>
        <template v-slot:is_print="{ row }">
          <span :class="'is_print' + row.is_print">
            {{ list.is_print_list[row.is_print] }}
          </span>
        </template>
        <template v-slot:pay_status="{ row }">
          <span :class="row.pay_status == 0 ? 'unpaid' : 'success'">
            {{ list.pay_type_list[row.pay_status] }}
          </span>
        </template>
        <template v-slot:is_prior_payment="{ row }">
          <span :class="'pay_type' + row.is_prior_payment">
            {{ list.is_piroment[row.is_prior_payment] }}
          </span>
        </template>
        <template v-slot:userNickname="{ row }">
          <span>{{ list.from_list[row.from] }}</span>
        </template>
        <template v-slot:returnOrder="{ row }">
          <span :style="{ color: row.is_receipt == 1 ? '#19b098' : '#ff5a5a' }">
            {{ row.is_receipt == 1 ? "是" : "否" }}
          </span>
        </template>
        <el-table-column
          label="管理操作"
          align="left"
          fixed="right"
          :width="tableWidth[hash + 'controls'] || 240"
          prop="controls"
          class-name="main_hei"
        >
          <template slot="header">
            <table-header-setting
              @openHeader="dialogFormVisible = true"
            ></table-header-setting>
          </template>
          <template slot-scope="scope">
            <el-link
              type="warning"
              v-if="
                scope.row.order_status == 0 && scope.row.is_prior_payment != 1
              "
              @click="
                (examineVisible = true), (id = scope.row.id), order_info()
              "
              >审核</el-link
            >
            <el-link
              @click="openEdit(scope.row.id)"
              v-if="isShow_edit(scope)"
              type="primary"
              >编辑</el-link
            >
            <el-link @click="openLook(scope.row.id)">查看</el-link>
            <el-link
              @click="print(scope.row.id, scope.row.uid)"
              v-if="scope.row.order_status != 0"
              >打印</el-link
            >
            <el-link
              @click="exportOrderiInfo(scope.row.id)"
              v-if="isShow_export(scope)"
              >导出</el-link
            >
            <el-link
              @click="(id = scope.row.id), successClick()"
              v-if="scope.row.order_status == 2 && scope.row.total >= 4"
              >收货</el-link
            >
            <template v-if="scope.row.total >= 4">
              <el-dropdown>
                <el-link type="danger" class="el-dropdown-link">更多</el-link>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item v-if="scope.row.order_status == 3"
                    ><div @click="receipt(scope.row.id)">
                      回单
                    </div></el-dropdown-item
                  >
                  <el-dropdown-item v-if="scope.row.order_status == 0"
                    ><div @click="print(scope.row.id, scope.row.uid)">
                      打印
                    </div></el-dropdown-item
                  >
                  <el-dropdown-item
                    ><div @click="exportOrderiInfo(scope.row.id)">
                      导出
                    </div></el-dropdown-item
                  >
                  <el-dropdown-item
                    v-if="
                      scope.row.order_status == 0 ||
                      scope.row.order_status == 1
                    "
                    ><div
                      v-if="scope.row.is_prior_payment == 0"
                      @click="(id = scope.row.id), cancelClick()"
                    >
                      取消
                    </div></el-dropdown-item
                  >
                  <router-link
                    :to="
                      '/order/list/add?id=' +
                      scope.row.id +
                      '&uid=' +
                      scope.row.uid
                    "
                  >
                    <el-dropdown-item>复制</el-dropdown-item>
                  </router-link>
                  <!-- <router-link
                    :to="'/order/list/check/' + scope.row.id"
                    v-if="scope.row.order_status == 2"
                  >
                    <el-dropdown-item>验收</el-dropdown-item>
                  </router-link> -->
                  <el-dropdown-item
                    v-if="
                      scope.row.order_status == 0 ||
                      scope.row.order_status == 1
                    "
                    ><div
                      @click="
                        (id = scope.row.id),
                          (splitVisible = true)
                      "
                    >
                      拆分
                    </div></el-dropdown-item
                  >
                  <!-- <el-dropdown-item v-if="scope.row.order_status == 2"
                    ><div @click="(id = scope.row.id), successClick()">
                      收货
                    </div></el-dropdown-item
                  > -->
                  <!-- scope.row.order_status != 2 &&
                      scope.row.is_prior_payment != 1 &&
                      scope.row.order_status != 3 -->
                  <el-dropdown-item
                    v-if="
                      scope.row.order_status == 2 ||
                      scope.row.order_status == 3
                    "
                    ><div @click="quit(scope)">退货</div></el-dropdown-item
                  >
                </el-dropdown-menu>
              </el-dropdown>
            </template>
            <template v-else>
              <el-link
                ><div @click="exportOrderiInfo(scope.row.id)">
                  导出
                </div></el-link
              >
              <el-link
                v-if="
                  scope.row.order_status == 0 || scope.row.order_status == 1
                "
                ><div
                  v-if="scope.row.is_prior_payment == 0"
                  @click="(id = scope.row.id), cancelClick()"
                >
                  取消
                </div></el-link
              >
              <!-- <router-link
              :to="
                '/order/list/add/' + scope.row.id + '?uid=' + scope.row.uid
              "
            > -->
              <el-link @click="openCopy(scope.row.id, scope.row.uid)"
                >复制</el-link
              >
              <!-- </router-link> -->
              <router-link
                :to="'/order/list/check/' + scope.row.id"
                v-if="scope.row.order_status == 2"
              >
                <el-link>验收</el-link>
              </router-link>
              <el-link
                v-if="
                  scope.row.order_status == 0 || scope.row.order_status == 1
                "
                ><div
                  @click="
                    (id = scope.row.id),
                      (splitVisible = true)
                  "
                >
                  拆分
                </div></el-link
              >
              <!-- <el-link v-if="scope.row.order_status == 2"
                ><div @click="(id = scope.row.id), successClick()">
                  收货
                </div></el-link
              > -->

              <el-link
                v-if="
                  scope.row.order_status == 2 || scope.row.order_status == 3
                "
                @click="quit(scope)"
                >退货</el-link
              >
            </template>
          </template>
        </el-table-column>
      </MainTable>
      <div class="main_num boxdq marginTop10">
        <div class="main_num_l boxha">
          <p>
            新增订单：
            <em>{{ list.today_order_num }}</em>
          </p>
          <p>
            下单金额：
            <em>{{ list.today_order_money }}</em>
          </p>
          <p>
            配送订单：
            <em>{{ list.today_send_num }}</em>
          </p>
          <p>
            预定金额：
            <em>{{ list.today_send_order_money }}</em>
          </p>
          <p>
            配送金额：
            <em>{{ list.today_send_money }}</em>
          </p>
          <!-- <p class="box" style="width: 400px; align-items: center">
            发货进度：
            <el-progress
              :text-inside="true"
              :stroke-width="18"
              :percentage="send_percent"
              status="success"
              color="#E47C02"
              style="width: 60%"
            ></el-progress>
          </p> -->
          <!-- <span class="main_num_ls">（*统计以当天配送时间为准）</span> -->
        </div>
        <!-- 分页 -->
        <div class="main_num_r">
          <MainPagination
            :current-page="current.page"
            :page-sizes="[10, 20, 30, 50, 100]"
            :page-size="limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="totalCount"
            background
            @size-change="changeLimit"
            @current-change="changePage"
          />
        </div>
      </div>
    </div>

    <!-- 表头设置 -->
    <el-dialog
      title="表头设置"
      :visible.sync="dialogFormVisible"
      class="main_dialog dialog500"
    >
      <div class="set_sort">
        <div class="set_none_show">
          <el-checkbox-group v-model="type">
            <el-checkbox
              v-for="(Header, index) in group"
              :key="index"
              :label="Header.id"
              :disabled="Header.disabled"
              >{{ Header.name }}</el-checkbox
            >
          </el-checkbox-group>
        </div>
        <div class="set_header_sort">
          <div class="set_sort_ab">
            <draggable
              chosen-class="chosen"
              v-model="group"
              @start="onStart"
              @end="onEnd"
              animation="500"
            >
              <transition-group>
                <li
                  class="set_sort_ab_border"
                  v-for="item in group"
                  :key="item.id"
                >
                  <div>
                    <span class="el-icon-d-caret"></span>
                    <span>{{ item.name }}</span>
                  </div>
                  <svg-icon icon-class="index_move" />
                </li>
              </transition-group>
            </draggable>
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="setupmine" v-repeatClick
          >确 定</el-button
        >
      </div>
    </el-dialog>
    <!-- 订单导入 -->
    <el-dialog
      title="订单导入"
      :visible.sync="importbuVisible"
      class="main_dialog dialog840 importbu"
    >
      <div class="dialog_padding20_30">
        <div class="importbu_p">
          <h3>导入说明：</h3>
          <p>1.注意使用红色字体标注的必填字段,不填或错填将导致导入失败。</p>
          <p>2.导入文件仅支持xlsx格式,大小不超过2M ,数据不超过2000行。</p>
          <p>3.导入文件不能包含“合并单元格”，否则无法导入。</p>
          <p>
            4.导入时碰到数据不正确的行，系统会跳过错误的行继续执行未完成的行。
          </p>
        </div>
        <div class="importbu_ul">
          <ul>
            <li>
              <p>选择用户标识</p>
              <el-radio-group v-model="import_form.user_type" :border="true">
                <el-radio :label="1">按用户编码导入</el-radio>
                <el-radio :label="2">按用户名称导入</el-radio>
              </el-radio-group>
            </li>
            <li>
              <p>选择商品标识</p>
              <el-radio-group v-model="import_form.goods_type" :border="true">
                <el-radio :label="1">按SKU编码导入</el-radio>
                <el-radio :label="2">按SPU编码导入</el-radio>
                <el-radio :label="3">按商品名称导入</el-radio>
              </el-radio-group>
            </li>
          </ul>
        </div>
        <div class="importbu_in">
          <h3>数据行区间设置</h3>
          <div class="box">
            <p>
              <span>第一个数据行号：</span
              ><el-input-number
                v-model="import_form.start_line_num"
                controls-position="right"
                :min="2"
              ></el-input-number>
            </p>
            <p>
              <span>最后一行数据行数：</span
              ><el-input
                v-model="import_form.end_line_num"
                placeholder="默认为全部"
                type="number"
              ></el-input>
            </p>
          </div>
        </div>
        <div class="importbu_an box">
          <el-button @click="downTemplate" class="marginRight10"
            >下载模板</el-button
          >
          <el-upload
            class="upload-demo"
            :action="order_import"
            :on-success="importSuccess"
            :on-error="importerr"
            :show-file-list="false"
            :data="import_params"
            :headers="{
              Authorization: getToken(),
            }"
          >
            <el-button size="small" @click="handleUpload" type="primary"
              >点击上传</el-button
            >
          </el-upload>

          <p v-if="import_file_name ? true : false">
            上传文件名：{{ import_file_name }}
          </p>
        </div>
        <div class="import_process" v-if="percentShow">
          <div class="progress">
            <el-progress
              :text-inside="true"
              :stroke-width="20"
              :percentage="percent"
              color="#19B098"
            ></el-progress>
          </div>
          <div class="notice" v-if="percentShow">
            <div class="importtips">
              <p class="success" v-if="percent == 100">订单导入结束</p>
              <div v-for="(item, index) in reverseSum" :key="index">
                <p v-if="item.type == 2" :key="index" class="fail">
                  {{ item.name }}，导入失败
                </p>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button :disabled="cancelDisabled" @click="importbuVisible = false"
          >取 消</el-button
        >
      </div>
    </el-dialog>
    <!-- 审核 -->
    <el-dialog
      title="审核"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :visible.sync="examineVisible"
      class="main_dialog dialog900"
    >
      <div class="dialog_padding20_30">
        <div class="main_xq">
          <ul class="boxha">
            <li>
              用户名称：<span>{{ examine_sh.member.nickname }}</span>
            </li>
            <li>
              配送日期：<span>{{
                parseTime(examine_sh.send_time, "{y}-{m}-{d}")
              }}</span>
            </li>
            <li>
              收货人：<span>{{ examine_sh.contact }}</span>
            </li>
            <li class="main_w100">
              收货地址：<span>{{ examine_sh.address }}</span>
            </li>
            <li class="main_w100">
              订单备注：<span>{{ examine_sh.remark }}</span>
            </li>
          </ul>
        </div>
        <div class="examine_he">
          合计:<span>￥{{ examine_sh.order_money }}</span>
        </div>
        <div class="main_table" style="height: 410px">
          <el-table
            ref="multipleTable1"
            v-loading="listLoading"
            :data="examine_sh.order_list"
            element-loading-text="加载中"
            fit
            border
            highlight-current-row
          >
            <el-table-column
              label="商品名称"
              prop="name"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              label="下单数量"
              prop="order_num"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              label="单价"
              prop="order_price"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              label="小计"
              prop="byname"
              :show-overflow-tooltip="true"
            >
              <template slot-scope="scope">{{
                (scope.row.order_num * scope.row.order_price) | twoPlace
              }}</template>
            </el-table-column>
            <el-table-column
              label="备注"
              prop="remark"
              :show-overflow-tooltip="true"
            />
          </el-table>
        </div>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="examine(1)" v-repeatClick
          >通 过</el-button
        >
        <el-button @click="examine(4)">取消订单</el-button>
        <el-button @click="examine_edit">编 辑</el-button>
      </div>
    </el-dialog>
    <!-- 拆分 -->
    <split :splitVisible.sync="splitVisible" :orderId="id"></split>
    <!-- 订单导出 -->
    <el-dialog
      title="订单导出"
      :visible.sync="exportbuVisible"
      class="main_dialog dialog500"
    >
      <div class="dialog_padding20_30">
        <div v-if="selectArr.length == 0 ? true : false">
          <p class="exptitle">选择配送日期</p>
          <el-date-picker
            v-model="exportTime"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            @change="dateChange"
          >
          </el-date-picker>
          <el-tooltip
            class="item"
            effect="dark"
            :content="time_content"
            placement="bottom"
          >
            <i class="el-icon-question"></i>
          </el-tooltip>
          <p class="exptitle" style="padding-top: 10px">用户</p>
          <div style="display: flex; flex-direction: row; align-items: center">
            <change-user-input
              ref="changeUserInput"
              @sendValue="getUser"
              @clear="clearUid"
            ></change-user-input>
            <el-select
              v-model="selectValue"
              multiple
              placeholder="请选择子账号"
              @change="changeNickname"
              v-if="showChildList"
            >
              <el-option
                v-for="item in options"
                :key="item.id"
                :label="item.nickname"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </div>
          <p class="exptitle" style="padding-top: 10px">订单状态</p>
          <el-select
            v-model.trim="export_status"
            class="wid240"
            placeholder="订单状态"
            multiple
            clearable
          >
            <el-option label="待审核" value="0"></el-option>
            <el-option label="备货中" value="1"></el-option>
            <el-option label="配送中" value="2"></el-option>
            <el-option label="已收货" value="3"></el-option>
            <el-option label="已取消" value="4"></el-option>
          </el-select>
        </div>
        <div>
          <p class="exptitle margintop">选择导出订单信息字段</p>
          <div>
            <el-checkbox-group
              v-model="exportHeaderType.orderList"
              @change="changeCheckBox($event)"
            >
              <el-checkbox
                v-for="(Header, index) in exportOrderLsit"
                :key="index"
                :label="Header.id"
                :disabled="Header.disabled"
                >{{ Header.name }}</el-checkbox
              >
              <el-checkbox :label="77">订单标签</el-checkbox>
            </el-checkbox-group>
          </div>
          <div>
            <el-checkbox v-model="goodspicker"
              >导出商品信息
              <el-tooltip
                class="item"
                effect="dark"
                content="默认不勾选，则不导出商品信息"
                placement="bottom"
              >
                <i class="el-icon-question"></i> </el-tooltip
            ></el-checkbox>
          </div>
        </div>
        <div v-if="goodspicker">
          <p class="exptitle margintop">选择导出商品字段信息</p>
          <el-checkbox-group v-model="exportHeaderType.goodsList">
            <el-checkbox
              v-for="(Header, index) in exportGoodsList"
              :key="index"
              :label="Header.id"
              :disabled="Header.disabled"
              >{{ Header.name }}</el-checkbox
            >
          </el-checkbox-group>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="exportbuVisible = false">取 消</el-button>
        <el-button type="primary" @click="exportConfirm" v-repeatClick
          >确 定</el-button
        >
      </div>
    </el-dialog>
    <!-- 打印子组件 -->
    <order-print
      ref="printTemplate"
      v-show="false"
      id="printname"
    ></order-print>
    <order-delivery
      ref="NewprintTemplate"
      v-show="false"
      id="printnames"
    ></order-delivery>
    <!-- 批量取消 -->
    <progress-diolog
      :title="`已选择${selectArr.length}个订单`"
      :visible.sync="cancelVisible"
      :percentage="cancelPercent"
      @close="cancelClose"
    >
      <div class="progress_list">
        <template v-for="(percentList, index) in cancelPercentList">
          <p :class="{'progress_list_red': percentList.type == 2}" :key="index">
            {{ `订单id:${percentList.order_id}，${percentList.msg}` }}
          </p>
        </template>
        <p v-if="cancelPercent == 100" class="progress_list_msg">
          已经完成请关闭弹框!
        </p>
      </div>
    </progress-diolog>
  </div>
</template>

<script>
import { orderListColumns, sortColumns } from './mockData'
import { mixins } from "@/mixins/index.js";
import dateOption from "@/options/dateOption";
import {
  order_index,
  order_info,
  batchCancelOrder,
  order_setOrderStatus,
  order_merge,
  order_batchReceive,
  order_export_info,
  order_export,
  order_info_detail,
  order_down_tem,
  exports_list,
} from "@/api/order/orderList";
import {
  field_save,
  setting_company,
  goods_getGoodsSpu,
  order_import,
} from "@/api/currency";
import { field_getField } from "@/api/sort";
import { apiUrl, objKeySort, Md5, packApi } from "@/utils/public";
import {
  parseTime,
  exportMethod,
  getNowMonth,
  JSONToExcelConvertor,
  fileDownLoad,
} from "@/utils/index";
import { orderListHeader, GoodsList } from "@/options/headerSet.js";
import OrderPrint from "@/views/order/orderPrint.vue";
import { mapGetters } from "vuex";
import draggable from "vuedraggable";
import { user_getMemberInfo } from "@/api/currency";
import OrderListSee from "./orderList_see.vue";
import { useType } from "@/api/distribution/distributionList";
import OrderDelivery from "@/views/order/orderDelivery.vue";
import { member_subAccount } from "@/api/user/user";
import split from './components/split/index.vue';
export default {
  mixins: [mixins],
  components: {
    OrderPrint,
    draggable,
    OrderListSee,
    OrderDelivery,
    split,
  },
  computed: {
    ...mapGetters(["avatar"]),
    reverseSum() {
      return this.percent_list;
    },
    send_percent() {
      let percent = 0;
      if (this.list.today_sent_num != 0) {
        percent = parseFloat(
          (this.list.today_sent_num / this.list.today_send_num) * 100
        ).toFixed(2);
      }
      return Number(percent);
    },
    isShow_edit() {
      return (scope) => {
        if (scope.row.order_status == 0 || scope.row.order_status == 1) {
          if (scope.row.is_prior_payment == 1 && scope.row.order_status == 0) {
            return false;
          }
          return true;
        } else {
          return false;
        }
      };
    },
    isShow_export() {
      return (scope) => {
        if (
          scope.row.order_status == 3 ||
          (scope.row.order_status == 1 && scope.row.is_prior_payment == 1)
        ) {
          if (scope.row.order_status == 0 || scope.row.order_status == 1) {
            return false;
          }
          return true;
        } else {
          return false;
        }
      };
    },
  },
  data() {
    return {
      orderListColumns,
      fileDownLoad,
      exportMethod,
      getNowMonth,
      // 时间
      parseTime,
      time_content: "",
      type_val: "",
      order_import: order_import,
      // 打印id
      printid: "",
      // 拆分
      splitVisible: false,
      // 审核
      examineVisible: false,
      examine_sh: {
        member: {
          nickname: "",
        },
      },
      split_chec: [],
      // 分页
      current: {
        page: 1,
        per_page: 20,
      },
      limit: 20,
      totalCount: 1,
      // 列表数据
      list: {
        today_sent_num: 0,
        today_send_num: 1,
        from_list: [],
        group: [],
        is_delivery: [],
        is_piroment: [],
        is_print_list: [],
        order_status_list: [],
        pay_type_list: [],
        salesman: [],
        driver: {},
        list: {
          data: [],
        },
      },
      listLoading: false,
      // 搜索
      form: {
        send_start_time: "", //配送日期
        send_end_time: "",
        order_sn: "",
        uid: "",
        from: "", //来源
        is_delivery_id: "", //运费
        is_piroment_id: "", //支付方式
        is_print: "",
        goods_spu_id: "", //商品
        send_time_id: null,
        create_start_time: "", //下单日期
        create_end_time: "",
        contact: "", //收货信息
        group_id: null,
        salesman_id: "", //业务员
        driver_id: "", //司机
        mobile: "",
        pay_type: null, //支付状态
        status: this.activeName,
        zid: "",
        package_menu_order_sn: '', //菜谱订单号
        send_time: null, // 配送日期排序
        nickname: null, // 用户名称排序
        user_code: null, // 用户编码排序
      },
      zid_name: [],
      createTime: [],
      sendTime: [],
      pickerOptions: dateOption,
      look_canceled_list: false,
      // 选中菜单
      activeName: null,
      // 更多
      moredata: false,
      // 全选
      selectArr: [],
      // 表头设置
      dialogFormVisible: false,
      type: [],
      Header: orderListHeader,
      // id
      id: "",
      // 订单导出
      exportbuVisible: false,
      goodspicker: false, //商品信息 true
      exportOrderLsit: orderListHeader,
      exportGoodsList: GoodsList,
      // 默认的导出表头信息
      exportHeaderType: {
        orderList: [],
        goodsList: [],
      },
      // 订单导出时间
      exportTime: [],
      export_user: "",
      export_status: [],
      // 订单导入
      importbuVisible: false,
      import_form: {
        user_type: 1,
        goods_type: 1,
        start_line_num: 2,
        end_line_num: "",
      },
      import_file_name: "",
      import_params: {
        string: "",
        admin_uid: "",
        admin_uid_company: "",
      },
      percent_gs: 0,
      percent: 0,
      percentShow: false,
      percent_list: [],
      importArrLength: 1,
      cancelDisabled: false,
      group: orderListHeader,
      ids: null,
      scrollTop: null,
      isPrint: false,
      isNewPrint: false,
      selectValue: [], // 选中的子账号数据
      options: [], // 子账号列表
      showChildList: false, // 子账号的展示和隐藏
      // 该字段用于判断批量打印按钮是否展示
      isPrintBtn: false,
      isPrintList: [],
      disabled: false,
      // 批量取消
      cancelTaskId: null, //事件ID
      cancelVisible: false, // 弹框
      cancelPercent: 0, // 进度条
      cancelPercentList: [], // 展示内容
    };
  },
  watch: {
    // 用于监听勾选订单时，展示批量打印按钮
    isPrintList: {
      handler(newVal) {
        this.isPrintBtn = newVal.length > 0 ? true : false;
      },
      deep: true,
    },
    "exportHeaderType.orderList": {
      handler(newVal) {
        let index = newVal.findIndex((item) => item == 19);
        this.showChildList = index == "-1" ? false : true;
      },
      deep: true,
      immediate: true,
    },
    "exportHeaderType.orderList": {
      handler(newVal) {
        let index = newVal.findIndex((item) => item == 19);
        this.showChildList = index == "-1" ? false : true;
      },
      deep: true,
      immediate: true,
    },
  },
  activated() {
    if (this.$route.params.activeName) {
      let activeName = this.$route.params.activeName;
      if (this.$route.params.today) {
        let time = this.parseTime(new Date(), "{y}-{m}-{d}");
        this.sendTime = [time, time];
      }
      this.activeName = String(activeName);
    }
    if (this.$route.params.time) {
      let time = this.$route.params.time;
      time = this.parseTime(time, "{y}-{m}-{d}");
      this.sendTime = [time, time];
    }

    if (this.$route.params.is_piroment) {
      this.form.is_piroment_id = this.$route.params.is_piroment;
    }
    // 列表
    let scrollTop = sessionStorage.getItem("scrollTop") || 0;
    this.$nextTick(() => {
      this.moredata = false;
      // this.reset()
      // this.getNumerical(235);
      let table = document.getElementsByClassName("el-table__body-wrapper");
      setTimeout(() => {
        this.$set(table[0], "scrollTop", scrollTop);
      }, 500);
      this.order_index();
    });
  },
  // 刷新
  inject: ["reload"],
  provide() {
    return {
      getOrderList: this.order_index,
    }
  },
  mounted() {
    if(this.$route.query.order_sn) {
      this.form.package_menu_order_sn = this.$route.query.order_sn
      this.getSearchFor()
    }else {
      this.sort_data();
    }
    let dom = this.$refs.orderTable.getScroll();
    dom.addEventListener(
      "scroll",
      (e) => {
        this.scrollTop = e.target.scrollTop;
      },
      { passive: true }
    );
    window.Echo.channel("bacthImportOrder." + this.avatar.company_id).listen(
      "BacthImportOrderEvent",
      (e) => {
        this.cancelDisabled = true;
        this.importArrLength = e.notice.count;
        this.percentShow = true;
        if (e.notice.code == 0) {
          this.percent_list.push({
            num: this.percent,
            type: 1,
            name: e.notice.msg,
          });
        } else if (e.notice.code == 100) {
          this.percent_list.push({
            num: this.percent,
            type: 2,
            name: e.notice.msg,
          });
        }
        this.percent_gs = parseInt(this.percent_gs) + 1;
        if ((this.percent_gs / this.importArrLength) * 100 >= 100) {
          this.percent = 100;
          this.cancelDisabled = false;
          return;
        }
        this.percent =
          this.percent_gs / this.importArrLength
            ? parseInt((this.percent_gs / this.importArrLength) * 100)
            : 0;
      }
    );
    this.setupEchoListeners(this.avatar.company_id);
  },
  methods: {
    //  表格双击跳转详情页面
    rowDblclick(row, column, event) {
      this.openLook(row.id)
    },
    // 设置事件监听器
    setupEchoListeners(company_id) {
      if(!window.Echo) return;
      window.Echo.channel(`batchCancelOrders.${company_id}`).listen(
        "BacthCancelOrdersEvent",
        (e)=> {
          console.log(e);
          let { rate, msg, order_id, code, task_id } = e.notice;
          if(this.cancelTaskId == task_id) {
            this.cancelPercent = parseInt(rate * 100);
            this.cancelPercentList.push({
              type: code == 200 ? 1 : 2,
              order_id: order_id,
              msg: msg,
            });
          }
        }
      )
    },
    // 获取子账号列表
    getChildList(uid) {
      // 子账号
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name, { pid: uid })) +
              apiUrl().appsecret
          ),
        },
        apiUrl().name,
        { pid: uid }
      );
      member_subAccount(data).then((res) => {
        if (res.errcode == 0) {
          this.options = res.data.list;
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    changeNickname(e) {
      console.log(e);
    },
    startGetting() {
      this.getSearchFor();
    },
    // 点击排序
    tableSortChange({column, prop, order}) {
      this.form.send_time = null;
      this.form.nickname = null;
      this.form.user_code = null;
      this.form[prop] = order;
      this.order_index();
    },

    // 搜索并折叠搜索条件
    getSearchFor() {
      this.getArticleList();
    },
    //清除子账号
    clearzid() {
      this.form.uid = "";
      this.form.zid = "";
      this.zid_name = [];
    },
    //展示子账号
    uidName(uid) {
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name)) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        { id: uid }
      );
      user_getMemberInfo(data).then((res) => {
        if (res.errcode == 0) {
          this.form.zid = "";
          this.form.zid_name = null;
          res.data.subAccount.map((e, ind) => {
            if (ind == 0) {
              e.id = 0;
              e.nickname = "主账号";
            }
          });
          res.data.subAccount.unshift({
            id: "",
            nickname: "所有",
          });
          this.zid_name = res.data.subAccount;
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    //排序
    sort_data() {
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name)) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        { type: 5 }
      );
      field_getField(data).then((res) => {
        let arry = JSON.parse(res.data.info.sort);
        if (arry || arry.length) {
          this.group.sort((a, b) => {
            return arry.indexOf(a.id) - arry.indexOf(b.id);
          });
        }
      });
    },
    //拖拽
    onStart() {},
    onEnd() {},
    // 勾选
    canceledChange(val) {
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(
              Object.assign(apiUrl().name, { look_canceled_list: val ? 1 : 0 })
            ) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        { look_canceled_list: val ? 1 : 0 }
      );
      setting_company(data).then((res) => {
        if (res.errcode == 0) {
          this.order_index();
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    // 审核
    order_info() {
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name, { id: this.id })) +
              apiUrl().appsecret
          ),
        },
        apiUrl().name,
        { id: this.id }
      );
      order_info(data).then((res) => {
        if (res.errcode == 0) {
          this.examine_sh = res.data.info;
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    examine(type, is_receipt) {
      let form = {
        id: this.id,
        status: type,
        is_receipt: is_receipt,
      };
      is_receipt ? "" : delete form.is_receipt;
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(
              Object.assign(apiUrl().name, { id: this.id, status: type })
            ) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        form
      );
      order_setOrderStatus(data).then((res) => {
        if (res.errcode == 0) {
          if (type == 1) {
            this.$message({
              message: "审核成功",
              type: "success",
            });
          } else if (type == 3) {
            this.$message({
              message: "确认成功",
              type: "success",
            });
          } else {
            this.$message({
              message: "取消成功",
              type: "success",
            });
          }
          this.order_index();
          this.examineVisible = false;
        } else if (res.errcode == 40035) {
          let msg = res.errmsg;
          this.examineVisible = false;
          this.$nextTick(() => {
            this.$alert(msg, "提示", {
              confirmButtonText: "确定",
              callback: (action) => {
                this.order_index();
              },
            });
          });
        } else {
          this.$message.error(res.errmsg);
          this.examineVisible = false;
        }
      });
    },
    examine_edit() {
      this.examineVisible = false;
      this.$router.push("/order/list/edit?id=" + this.id);
    },
    // 取消
    cancelClick() {
      this.$confirm("确认取消订单?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.examine(4);
        })
        .catch(() => {});
    },
    // 收货
    successClick() {
      this.$myConfirm("确认订单用户已完成签收?", "提示", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        threesButtonText: "确认并回单",
        type: "warning",
      })
        .then((val) => {
          if (val == 1) {
            this.examine(3);
          } else if (val == 2) {
            this.examine(3, 1);
          }
        })
        .catch(() => {});
      // this.$confirm("确认订单用户已完成签收?", "提示", {
      // 	confirmButtonText: "确定",
      // 	cancelButtonText: "取消",
      // 	type: "warning",
      // })
      // 	.then(() => {
      // 		this.examine(3);
      // 	})
      // 	.catch(() => {});
    },
    // 回单
    receipt(id) {
      this.id = id;
      this.$confirm("确认该订单已经回单吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.examine(3, 1);
        })
        .catch(() => {});
    },
    openLook(id) {
      sessionStorage.setItem("scrollTop", this.scrollTop);
      this.$router.push({
        path: "/order/list/see",
        query: { id: id },
      });
    },
    openEdit(id) {
      sessionStorage.setItem("scrollTop", this.scrollTop);
      this.$router.push({
        path: "/order/list/edit",
        query: { id: id },
      });
    },
    openCopy(id, uid) {
      sessionStorage.setItem("scrollTop", this.scrollTop);
      this.$router.push({
        path: "/order/list/add",
        query: { id: id, uid: uid },
      });
    },
    // 退货
    quit(scope) {
      let uid = scope.row.uid;
      let id = scope.row.id;
      let return_status = scope.row.return_status;
      if (return_status == 2) {
        this.$message.warning("订单已全部退货，无法再继续退货！");
        return;
      }
      sessionStorage.setItem("scrollTop", this.scrollTop);
      this.$router.push({
        name: "order_return_add",
        params: { uid: uid, id: id, return_status: return_status },
      });
    },

    // 选中菜单
    handleClick(tab, event) {
      this.form = {
        send_start_time: "", //配送日期
        send_end_time: "",
        order_sn: "",
        uid: "",
        from: "", //来源
        is_delivery_id: "", //运费
        is_piroment_id: "", //支付方式
        is_print: "",
        goods_spu_id: "", //商品
        send_time_id: null,
        create_start_time: "", //下单日期
        create_end_time: "",
        contact: "", //收货信息
        group_id: null,
        salesman_id: "", //业务员
        driver: "", //司机
        mobile: "",
        pay_type: null, //支付状态
      };
      if (this.$refs["changeUserInput_form"]) {
        this.$refs["changeUserInput_form"].name = "";
      }
      this.current.page = 1;
      this.current.per_page = 20;
      this.limit = 20;
      this.order_index();
    },
    // 更多
    more() {
      this.moredata = !this.moredata;
    },
    // 监听全选
    handleSelectionChange(val) {
      this.selectArr = [];
      this.isPrintList = [];
      val.map((item) => {
        this.selectArr.push({ id: item.id });
        this.isPrintList.push({ id: item.id, uid: item.uid });
      });
    },
    // 批量打印
    pldeliver() {
      if (this.isPrintList.length != 0) {
        let length = this.isPrintList.length;

        this.$confirm(
          `此操作将连续打印【${length}】张配送单,并且打印机需要设置为后进纸,是否继续?`,
          "提示",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }
        )
          .then(async () => {
            for (let index = 0; index < this.isPrintList.length; index++) {
              const item = this.isPrintList[index];
              await this.print(item.id, item.uid, "continuous");
            }
          })
          .catch(() => {});
      } else {
        this.$message.error("请勾选订单");
      }
    },
    // 合并订单
    merge() {
      if (this.selectArr.length != 0) {
        this.$confirm("确定合并订单?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            let data = Object.assign(
              {
                sign: Md5(
                  objKeySort(Object.assign(apiUrl().name)) + apiUrl().appsecret
                ),
              },
              apiUrl().name,
              { ids: JSON.stringify(this.selectArr) }
            );
            order_merge(data).then((res) => {
              if (res.errcode == 0) {
                this.$message({
                  message: "合并成功",
                  type: "success",
                });
                this.order_index();
              } else {
                this.$message.error(res.errmsg);
              }
            });
          })
          .catch(() => {});
      } else {
        this.$message.error("请勾选订单");
      }
    },
    // 批量取消
    handleCancels() {
      if(!this.selectArr.length) return this.$message.error("请勾选订单");
      let length = this.selectArr.length;
      let order_ids = this.selectArr.map((e) => e.id).join(",");
      this.$confirm(`是否批量取消`,"提示",{
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.batchCancelOrder({ order_ids });
      }).catch(() => {});
    },
    batchCancelOrder(data) {
      batchCancelOrder(packApi(data)).then(res=> {
        if(res.errcode == 0) {
          this.cancelVisible = true;
          this.cancelTaskId = res.data.task_Id;
        }else {
          this.$message.error(res.errmsg);
        }
      })
    },
    // 批量弹框取消
    cancelClose() {
      this.cancelTaskId = null;
      this.cancelPercent = 0;
      this.cancelPercentList = [];
      this.order_index();
    },
    // 批量收货
    bulkGoods() {
      if (this.selectArr.length != 0) {
        let length = this.selectArr.length;
        let ids = this.selectArr.map((e) => {
          return e.id;
        });
        let form = {
          ids: ids.join(","),
        };
        this.$myConfirm(`确认批量完成【${length}】条订单？`, "提示", {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          threesButtonText: "确认并回单",
          type: "warning",
        })
          .then((val) => {
            if (val == 1) {
              this.batchReceive(form, 1);
            } else if (val == 2) {
              form.is_receipt = 1;
              this.batchReceive(form, 2);
            }
          })
          .catch(() => {});
        // this.$confirm(`确认批量完成【${length}】条订单？`, "提示", {
        // 	confirmButtonText: "确定",
        // 	cancelButtonText: "取消",
        // 	type: "warning",
        // })
        // 	.then(() => {
        // 		this.order_batchReceive(form);
        // 	})
        // 	.catch(() => {});
      } else {
        this.$message.error("请勾选订单");
      }
    },
    // 批量回单
    bulkReceipt() {
      if (this.selectArr.length != 0) {
        let length = this.selectArr.length;
        let ids = this.selectArr.map((e) => {
          return e.id;
        });
        let form = {
          ids: ids.join(","),
          is_receipt: 1,
        };
        this.$confirm(`已选中【${length}】条订单，确认都已回单？`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.batchReceive(form, 3);
          })
          .catch(() => {});
      } else {
        this.$message.error("请勾选订单");
      }
    },
    // 批量收货&&批量回单请求
    batchReceive(form, type) {
      let message = {
        1: "批量收货已完成",
        2: "批量收货并已回单",
        3: "批量回单已完成",
      };
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name)) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        form
      );
      order_batchReceive(data).then((res) => {
        if (res.errcode == 0) {
          this.$message({
            message: message[type],
            type: "success",
          });
          this.order_index();
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    // 导出框
    exportb() {
      this.time_content = "时间范围只能选择二个月之内";
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name)) + apiUrl().appsecret
          ),
        },
        apiUrl().name
      );
      order_export_info(data).then((res) => {
        if (res.errcode == 0) {
          this.exportHeaderType.orderList = res.data.list.type_10;
          this.exportHeaderType.goodsList = res.data.list.type_11;
        }
        this.exportbuVisible = true;
      });
    },
    changeCheckBox(e) {
      let index = e.findIndex((item) => item == 19);
      if (index == "-1") {
        this.selectValue = [];
      }
      this.showChildList = index == "-1" ? false : true;
    },
    // 下载模板
    downTemplate() {
      let form = {
        user_type: this.import_form.user_type,
        goods_type: this.import_form.goods_type,
      };
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name)) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        form
      );
      const notify = this.$notify.info({
        title: "开始导出...",
        type: "success",
        duration: 0,
      });
      order_down_tem(data).then((res) => {
        this.exportMethod(res, "订单导入模板", notify);
      });
    },
    // 导入订单
    importDialog() {
      this.import_file_name = "";
      this.percent_gs = 0;
      this.percent = 0;
      this.percentShow = false;
      this.percent_list = [];
      this.importArrLength = 1;
      this.cancelDisabled = false;
      this.importbuVisible = true;
    },

    importerr(err, file, fileList) {
      this.$message.error("上传失败");
    },
    importSuccess(response, file, fileList) {
      if (response.errcode != 0) {
        this.$message.error(response.errmsg);
        return;
      }
      this.import_file_name = file.name;
    },
    handleUpload() {
      this.import_params.string =
        this.import_form.start_line_num + "," + this.import_form.end_line_num;
    },
    //获取用户信息
    getUser(data) {
      let uid = data.info.user_id;
      if (uid) {
        this.getChildList(uid);
      }
      this.export_user = uid;
    },
    // 清除用户的uid
    clearUid() {
      this.export_user = "";
      this.selectValue = [];
      this.options = [];
    },
    exportConfirm() {
      this.listLoading = true;
      // 订单表头
      let orderList = [];
      this.exportOrderLsit.map((e) => {
        this.exportHeaderType.orderList.map((p) => {
          if (e.id == p) {
            orderList.push(e.id);
            return;
          }
        });
      });
      if(this.exportHeaderType.orderList.includes(77)) orderList.push(77);
      let goodsList = [];
      this.exportGoodsList.map((e) => {
        this.exportHeaderType.goodsList.map((p) => {
          if (e.id == p) {
            goodsList.push(e.id);
            return;
          }
        });
      });
      let ids = [];
      if (this.selectArr.length > 0) {
        this.selectArr.forEach((item) => {
          ids.push(item.id);
        });
      }
      let time = "";
      if (this.exportTime) {
        time = this.exportTime.join(" ");
      }
      let zids = null;
      if (this.showChildList) {
        zids = this.selectValue.join(",");
      }
      let form = {
        ids: ids.join("-"),
        order_head: orderList.join("-"),
        list_head: goodsList.join("-"),
        is_status: this.goodspicker ? 1 : 0,
        send_time: time,
        export_user: this.export_user,
        status: this.export_status.join(","),
        format: this.type_val,
        zids,
      };
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name, form)) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        form
      );
      if (!data.send_time && !data.ids) {
        this.$message.warning("请选择导出的配送时间段或导出的订单");
        return false;
      }
      // 储存导出的订单字段
      let data2 = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name, { type: 10 })) +
              apiUrl().appsecret
          ),
        },
        apiUrl().name,
        {
          type: 10,
          fields: JSON.stringify(orderList),
        }
      );
      // 储存导出的商品字段
      let data3 = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name, { type: 11 })) +
              apiUrl().appsecret
          ),
        },
        apiUrl().name,
        {
          type: 11,
          fields: JSON.stringify(goodsList),
        }
      );
      field_save(data2).then((res) => {
        if (res.errcode != 0) {
          // this.$message.error(res.errmsg);
        }
      });
      field_save(data3).then((res) => {
        if (res.errcode != 0) {
          // this.$message.error(res.errmsg);
        }
      });
      const notify = this.$notify.info({
        title: "开始导出...",
        type: "success",
        duration: 0,
      });
      // 导出数据
      order_export(data).then((res) => {
        this.listLoading = false;
        // if (this.type_val) {
        //   this.exportMethod(res, "订单列表.csv", notify);
        // } else {
        this.exportMethod(res, "订单列表", notify);
        // }
      });
      this.exportbuVisible = false;
    },
    // 日期选择
    dateChange(val) {
      let start = new Date(val[0]).getTime();
      let end = new Date(val[1]).getTime();
      let qj_time = parseInt(Math.abs(start - end) / 1000 / 60 / 60 / 24);
      // if (!this.type_val) {
      //   if (qj_time >= 7) {
      //     this.$message.warning(
      //       "选择时间跨度不能超过7天,如需选择更长时间,请使用“csv导出”"
      //     );
      //     this.exportTime = "";
      //   } else {
      //     this.exportTime = val;
      //   }
      // } else {
      if (qj_time >= 62) {
        this.$message.warning("选择时间跨度不能超过两个月");
        this.exportTime = "";
      } else {
        this.exportTime = val;
      }
      // }
    },
    // 详情导出
    // 导出
    exportOrderiInfo(id) {
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name)) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        { id: id }
      );
      const notify = this.$notify.info({
        title: "开始导出...",
        type: "success",
        duration: 0,
      });
      order_info_detail(data)
        .then((res) => {
          this.exportMethod(res, "订单详情", notify);
        })
        .catch(() => {
          this.$message.error("导出失败");
        });
    },
    // 打印
    print(id, uid, continuous = null) {
      return new Promise((resolves, rejects) => {
        let that = this;
        this.disabled = true;
        this.printid = id;
        useType({ uid }).then((res) => {
          new Promise((resolve, reject) => {
            if (res.errcode == 0) {
              let type = res.is_new == "1" ? "NewprintTemplate" : "printTemplate";
              resolve(type);
            } else {
              this.$message.error(res.errmsg);
            }
          }).then((res) => {
            this.$refs["NewprintTemplate"].show = false;
            this.$refs["printTemplate"].show = false;
            this.$refs[res].$emit("demo", {
              id: id,
              uid: uid,
              type: "order",
              continuous: continuous,
              cd: (res) => {
                resolves();
              },
            });
          });
        });
      });
    },
    // 设置确认
    setupmine() {
      let arry = [];
      let arrys = [];
      this.group.map((e) => {
        arrys.push(e.id);
        this.type.map((p) => {
          if (e.id == p) {
            arry.push(e.id);
            return;
          }
        });
      });
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name, { type: 5 })) +
              apiUrl().appsecret
          ),
        },
        apiUrl().name,
        {
          type: 5,
          fields: JSON.stringify(arry),
          sort: JSON.stringify(arrys),
        }
      );
      field_save(data).then((res) => {
        if (res.errcode == 0) {
          this.$message({
            message: "设置成功",
            type: "success",
          });
          this.reload();
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    // 搜索
    getArticleList() {
      this.current.page = 1;
      this.order_index();
    },
    // 重置
    reset() {
      this.$refs["userListFrom"].resetFields();
      if (this.$refs["changeGoodsInput"]) {
        this.$refs["changeGoodsInput"].name = "";
      }
      if (this.$refs["changeUserInput_form"]) {
        this.$refs["changeUserInput_form"].name = "";
      }
      this.createTime = [];
      this.sendTime = [];
      this.order_index();
    },
    // 分页
    changeLimit(pageSize) {
      this.current.per_page = pageSize;
      this.order_index();
    },
    changePage(page) {
      this.current.page = page;
      this.order_index();
    },
    // 列表
    order_index() {
      this.listLoading = true;
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(
              Object.assign(apiUrl().name, this.list_form(), this.current, {
                status: this.activeName,
              })
            ) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        this.list_form(),
        this.current,
        { status: this.activeName }
      );
      order_index(data).then((res) => {
        this.listLoading = false;
        if (res.errcode == 0) {
          const btnList = [7, 6, 5, 4]
          res.data.list.data.map((e) => {
            e.usercode = e.member.info ? e.member.info.code : null;
            e.total = btnList[e.order_status] || 3;
            e.show = false;
            e.salesman_id = e.salesman_id ? e.salesman ? e.salesman.name : '' : ''
            e.driver = e.driver_id ? e.driver ? e.driver.name : '' : ''
            e.line = e.line ? e.line.title : ''
            e.zid = e.zid_info? e.zid_info.nickname : ''
            e.send_time = parseTime(e.send_time, "{y}-{m}-{d}")
            e.created_at = parseTime(e.created_at, "{y}-{m}-{d} {h}:{i}:{s}")
          });

          this.look_canceled_list =
            res.data.look_canceled_list == 1 ? true : false;
          this.type = res.data.field;
          this.list = res.data;
          this.totalCount = res.data.list.total;
          this.import_params.admin_uid = res.data.admin_uid;
          this.import_params.admin_uid_company = res.data.admin_uid_company;
          this.orderListColumns = sortColumns(this.orderListColumns, res.data.field);
          // 在数据更新后执行
          this.$nextTick(() => {
            // myTable是表格的ref属性值
            if (this.$refs.multipleTable && this.$refs.multipleTable.doLayout) {
              this.$refs.multipleTable.doLayout();
            }
          });
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    list_form() {
      let form = JSON.parse(JSON.stringify(this.form));
      form.send_start_time = this.sendTime[0] ? this.sendTime[0] : "";
      form.send_end_time = this.sendTime[1] ? this.sendTime[1] : "";
      if (this.createTime != null) {
        form.create_start_time = this.createTime[0] ? this.createTime[0] : "";
        form.create_end_time = this.createTime[1] ? this.createTime[1] : "";
      }
      return form;
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/styles/variables.scss";
@import "@/styles/newIndex.scss";
.el-dropdown-menu--small .el-dropdown-menu__item {
  padding: 2px 20px;
}
.main-controls-wrap>div:first-child .el-button {
  margin-right: 6px;
  &.mg-l-6 {
    margin-left: 6px;
  }
}
.main_ti {
  padding-bottom: 1px;
  position: relative;
  /deep/.el-tabs__header {
    margin: 0;
  }
  /deep/.el-checkbox {
    margin-top: 12px;
  }
  &::after {
    height: 1px;
    content: "";
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    background-color: #e4e7ed;
    z-index: 1;
  }
  /deep/.el-tabs__nav-wrap::after {
    height: 0;
  }
}
.main_dialog {
  .main_table {
    /deep/.el-table__body-wrapper {
      overflow-y: auto;
      height: 300px;
    }
  }
  .main_xq ul li {
    width: 33.33%;
    margin-top: 5px;
    margin-bottom: 5px;
  }
  .examine_he {
    font-size: 16px;
    text-align: right;
    margin-top: 20px;
    span {
      color: red;
    }
  }
}

// 导出订单表头
.exptitle {
  display: block;
  font-size: 16px;
  color: #000000;
  margin: 0 0 10px;
  cursor: pointer;
}
.margintop {
  padding-top: 15px;
}
.el-checkbox-group {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  .el-checkbox {
    width: 25%;
  }
}

// 导入进度条
.import_process {
  width: 100%;
}

.progress {
  padding: 15px 40px 15px 0;
  // display: flex;
  // justify-content: center;
  // align-items: center;
}
.notice {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding-right: 40px;
  .importtips {
    overflow-y: auto;
    width: 100%;
    height: 84px;
    height: 84px;
    background: #ffffff;
    border: 1px solid #d8d8d8;
    padding: 10px 15px;
    .fail {
      color: #ff5a5a;
      line-height: 1.2;
      font-size: 12px;
    }
    .success {
      color: #19b098;
      line-height: 1.2;
      font-size: 12px;
    }
  }
}
// 支付状态
.success {
  color: $green;
}
.unpaid {
  color: $colour_red;
}
// 订单状态
.order0 {
  color: $order_color0;
}
// 订单状态
.order1 {
  color: $order_color1;
}
.order2 {
  color: $order_color2;
}
.order3 {
  color: $order_color3;
}
.order4 {
  color: $order_color4;
}
// 打印状态
.is_print0 {
  color: $colour_red;
}
.is_print1 {
  color: $green;
}
// 支付方式
.pay_type0 {
  color: $order_color1;
}
.pay_type1 {
  color: $green;
}
.new_navbar_svg {
  margin-left: 5px;
}
.temporary_svg {
  vertical-align: bottom;
}
.order_dervie {
  width: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  span:hover {
    color: #03a98e;
    cursor: pointer;
  }
  .order_dervie_content {
    margin-bottom: 8px;
  }
}
.mainor_sec {
  display: flex;
}
/deep/.el-dialog {
  width: 560px !important;
}
/deep/.el-dialog__body {
  padding: 0 !important;
}
/deep/.el-form-item--small.el-form-item {
  margin-bottom: 10px;
}

.multipleTable {
  overflow-y: auto;
}
/deep/.el-table__body tr.current-row > td.el-table__cell,
.el-table__body tr.selection-row > td.el-table__cell {
  background: none;
}
.progress_list {
  margin-top: 10px;
  max-height: 300px;
  overflow-y: auto;
  p {
    height: 24px;
    line-height: 24px;
  }
  .progress_list_red {
    color: red;
  }
  .progress_list_msg {
    color: #03a98e;
  }
}
</style>
